var ns, app, dialog, toast;
app = new Vue({
    el: '#app',
    data: {
        // IsAccept:同意,IsReject:拒绝,IsRevoke:撤销,
        list: [],
        form: {
            ID:0,
            pageindex: 0,
            pagesize: 10,
            keywords:'',
            status: 1, //状态（1-待处理 2-已处理 3-我发起的 4-我收到的）
            selectType:[],
        },
        menuType:[
            {'ID':1,'Title':'采购申请'},
            {'ID':2,'Title':'优惠减免'},
            {'ID':9,'Title':'通知公告'},
            {'ID':10,'Title':'房屋租售'},
            {'ID':11,'Title':'社区活动'},
            {'ID':12,'Title':'社区新闻'},
            {'ID':13,'Title':'问卷调查'},
            {'ID':14,'Title':'社区投票'},
            {'ID':15,'Title':'生活服务'},
            {'ID':16,'Title':'放行条'},
            {'ID':17,'Title':'装修登记'},
            {'ID':18,'Title':'外包合同'},
            {'ID':19,'Title':'外包合同付款'},
            {'ID':20,'Title':'外包合同罚款'},
            {'ID':21,'Title':'员工入职'},
            {'ID':22,'Title':'员工转正'},
            {'ID':23,'Title':'员工离职'},
            {'ID':24,'Title':'员工调动'},
            {'ID':25,'Title':'员工奖励'},
            {'ID':26,'Title':'员工处罚'},
            {'ID':27,'Title':'员工劳动合同'},
            {'ID':28,'Title':'员工休假'},
            {'ID':29,'Title':'用印申请'},
            {'ID':30,'Title':'通用申请'}
        ],
        current_item_length:0,
        total:0,
        can_scroll: false,
        showsearch:false,
        showTop:false,
        showsearchresult:false,
        searchresult:'',
        selectlist:[],

        oldScrolltop:0,
        scrollFlag:true,
        Interval:null,
        firstID:0,
        checked:false,
        Read:false,

        
    },

    methods: {
        get_data: function () {
            var that = this;
            that.can_scroll = false;
            var options = {};
            options.Keywords = that.form.keywords;
            options.pagesize = that.form.pagesize;
            options.pageindex = that.form.pageindex;
            options.typeList = JSON.stringify(that.form.selectType);
            options.IsReadonly=that.Read;
            if (that.form.pageindex >= 10){
                toast.loading({
                    title: "提交中",
                    duration: 2000
                }, function(ret) {});
            }
            options.action = "getapprovalpendinglist";
            console.log(JSON.stringify(options));
            ns.post(options, function (succeed, data, err) {
                console.log(JSON.stringify(data));
                if (succeed) {
                    if(data.list.length>0){
                        for(var i=0;i<data.list.length;i++){
                            data.list[i].AddTime=ns.SetTime_style(data.list[i].AddTime);
                        }
                    }
                    
                    if (data.list.length == that.form.pagesize) {
                        that.can_scroll = true;
                    }
                    if (that.form.pageindex == 0) {
                        that.list = data.list;
                    } else {
                        that.list = that.list.concat(data.list);
                    }
                    app.current_item_length = that.list.length;
                    that.total=data.number;
                    // if(that.scrollFlag){
                    //     that.scrollToBottom();
                    // }
                   
                    if(that.form.ID){
                        setTimeout(function() {
                            that.do_scrollTo();
                        }, 1000)
                    }
                    api.sendEvent({
                        name:'isreadExamine'
                    })
                } else if (err) {
                    //that.list = [];
                    // that.current_item_length = 0;
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        choose_noread:function(){
            var that=this;
            that.Read=!that.Read;
            that.list=[];
            that.get_data();
            // that.checked=!that.checked;
            // console.log(JSON.stringify(that.checked));
        },
        All_read:function(){
            var that=this;
            var options={};
            options.action='auditmessageread';
            ns.post(options, function (succeed, data, err){
                console.log(JSON.stringify(data));
                if(succeed){
                    if(data.status){
                        api.toast({
                            msg: data.Msg,
                            duration: 2000,
                            location: 'bottom'
                        });
                    }

                }else{
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            })
        },
        //翻页第一条数据的位置
        do_scrollbtn:function(id){
            　　　　 var sollid = document.getElementById('scroll'+id);
            　　　　 window.scrollTo(0,sollid.offsetTop); 
            　　},

        select_status: function (status) {
            var that = this;
            that.showTop=false;
            that.showsearchresult=true;
            if(status==1){
                that.searchresult='采购申请';
                that.form.selectType=[1];
            }
            if(status==2){
                that.searchresult="优惠申请";
                that.form.selectType=[2];
            }
            if(status==9){
                that.searchresult="通知公告";
                that.form.selectType=[9];
            }
            if(status==10){
                that.searchresult="房屋租售";
                that.form.selectType=[10];
            }
            if(status==11){
                that.searchresult="社区活动";
                that.form.selectType=[11];
            }
            if(status==12){
                that.searchresult="社区新闻";
                that.form.selectType=[12];
            }
            if(status==13){
                that.searchresult="问卷调查";
                that.form.selectType=[13];
            }
            if(status==14){
                that.searchresult="社区投票";
                that.form.selectType=[14];
            }
            if(status==15){
                that.searchresult="生活服务";
                that.form.selectType=[15];
            }
            if(status==16){
                that.searchresult="放行条";
                that.form.selectType=[16];
            }
            if(status==17){
                that.searchresult="装修登记";
                that.form.selectType=[17];
            }
            if(status==18){
                that.searchresult="外包合同";
                that.form.selectType=[18];
            }
            if(status==19){
                that.searchresult="外包合同付款";
                that.form.selectType=[19];
            }
            if(status==20){
                that.searchresult="外包合同罚款";
                that.form.selectType=[20];
            }
            if(status==21){
                that.searchresult="员工入职";
                that.form.selectType=[21];
            }
            if(status==22){
                that.searchresult="员工转正";
                that.form.selectType=[22];
            }
            if(status==23){
                that.searchresult="员工离职";
                that.form.selectType=[23];
            }
            if(status==24){
                that.searchresult="员工调动";
                that.form.selectType=[24];
            }
            if(status==25){
                that.searchresult="员工奖励";
                that.form.selectType=[25];
            }
            if(status==26){
                that.searchresult="员工处罚";
                that.form.selectType=[26];
            }
            if(status==27){
                that.searchresult="员工劳动合同";
                that.form.selectType=[27];
            }
            if(status==28){
                that.searchresult="员工休假";
                that.form.selectType=[28];
            }
            that.form.pageindex=0;
            
            that.list = [];
            that.get_data();
        },
        do_closearch:function(){
            var that=this;
            that.showsearchresult=false;
            that.form.selectType=[];
            that.list = [];
            that.get_data();

        },
        do_search: function() {
            this.get_data();
        },

        openGongdan: function (ApprovalID,ItemType,JpushLogID) {
            var that = this;
            var options={};
            options.action="jpushlogusersetread";
            options.JpushLogID=JpushLogID;
            ns.post(options, function (succeed, data, err) {
                if(succeed){
                    that.get_data();
                }
            });
            if(ItemType==18||ItemType==19||ItemType==20){
                ns.openWin('examine_detail_hetong', '合同详情', {
                    ApprovalID: ApprovalID,
                    Type:ItemType
                });

            }else if(ItemType==21||ItemType==22||ItemType==23||ItemType==24||ItemType==25||ItemType==26||ItemType==27||ItemType==28||ItemType==29||ItemType==30){
                ns.openWin('examine_detail_yg_bangong', '审批详情', {
                    ApprovalID: ApprovalID,
                    Type:ItemType
                });
            }
            else{
                ns.openWin('examine_detail', '审批详情', {
                    ApprovalID: ApprovalID,
                    Type:ItemType
                });

            }
        },
        open_renwu:function(){
            ns.openWin('examine_renwulist', '审批待办');
        },
        //同意
        do_open_sure:function(ApprovalID){
            var that = this;
            var options = {};
            options.ApprovalID = ApprovalID;
            options.Type=1;
            options.action = "getisoperate";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if (data.status == true) {
                        ns.openWin('examine_yes', '审批建议', {
                            IsReject: 0,
                            ApprovalID: ApprovalID,
                        });
                    } else {
                        api.toast({
                            msg: '状态已改变，请重新选择',
                            duration: 2000,
                            location: 'bottom'
                        });
                        that.get_data();
                    }
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        select_allstatus:function(){
            var that=this;
            that.showsearch=!that.showsearch;
            that.showTop=false;
            var options={};
            options.typeList = JSON.stringify(that.form.selectType);
            options.action = "getapprovalpendinglist";
            ns.post(options, function (succeed, data, err) {
                if(succeed){
                    that.selectlist=data.list;
                    
                }else{
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }

            });
            

        },
        
        open_select:function(){
            var that=this;
            that.showTop=!that.showTop;
            that.showsearch=false;

        },
        doHideSearch:function(){
            var that=this;
            that.showTop=false;
            that.showsearch=false;
        },
        //拒绝
        do_open_jujue:function(ApprovalID){
            var that = this;
            var options = {};
            options.ApprovalID = ApprovalID;
            options.Type=2;
            options.action = "getisoperate";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if (data.status == true) {
                        ns.openWin('examine_yes', '审批建议', {
                            IsReject: 1,
                            ApprovalID: ApprovalID,
                        });
                    } else {
                        api.toast({
                            msg: '状态已改变，请重新选择',
                            duration: 2000,
                            location: 'bottom'
                        });
                        that.get_data();
                    }
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });

        },
        //撤销
        doRevoke:function(ApprovalID){
            var that=this;
            var options = {};
            options.ApprovalID = ApprovalID;  
            options.action = "approvalrevoke";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if (data.status == true) {
                        api.toast({
                            msg: '撤销成功',
                            duration: 2000,
                            location: 'bottom'
                        });
                        that.get_data();
                    } else if (err) {
                        api.toast({
                            msg: err,
                            duration: 2000,
                            location: 'bottom'
                        });
                    }
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        //搜索结果返回位置
        do_scrollTo:function(){
            var that = this;
    　　　　 var sollid = document.getElementById('scroll'+that.form.ID);
    　　　　 window.scrollTo(0,sollid.offsetTop); 
            var classlist=document.getElementById('scroll'+that.form.ID).getElementsByClassName('boxbg')[0];
            classlist.style.backgroundColor = "#eaf1ff";
            setTimeout(function() {
                classlist.style.backgroundColor = "#f7fbff";
            }, 800)
    　　},
    }
});

apiready = function () {

    api.parseTapmode();

    ns = window.Foresight.Util;

    dialog = new auiDialog();

    toast = new auiToast();

    app.form.servicetype = api.pageParam.servicetype || 1;
    app.form.ID = api.pageParam.ID || 0;
 
    app.form.RoomID = api.pageParam.id || 0;

    app.form.isviewdetail = api.pageParam.isviewdetail || false;

    if (app.form.isviewdetail) {
        app.form.status = 4;
    }

    app.form.onlybaoshi = api.pageParam.onlybaoshi || 0;


    // ns.init_pull(true,true);
    ns.init_pull();

    // ns.init_search();

    app.get_data();

    api.addEventListener({
        name: 'reloadexaminelist'
    }, function (ret, err) {
        app.form.isFirstLoad = 1;
        app.get_data();
    });
    api.addEventListener({
        name: 'customerservicelist_frm'
    }, function (ret, err) {
        app.form.isFirstLoad = 1;
        app.get_data();
    });
    api.addEventListener({
        name: 'is_hidden_right',
    }, function (ret, err) {
        app.form.isFirstLoad = 1;
        app.get_data();
    });
    // api.addEventListener({
    //     name: 'do_open_select'
    // }, function(ret, err) {
    //     app.open_select();
    // });

    // api.addEventListener({
    //     name: 'do_open_service_jindu'
    // }, function(ret, err) {
    //     app.doOpenServiceProcess();
    // });
};
